<template>
  <el-button round @click="addNewForm">{{ button.buttonName }}</el-button>
</template>
<script setup>
import {DefaultMenuButton} from '@/components/form/DefaultFormDefinition';
import {getCurrentInstance, watchEffect} from 'vue';

const internalInstance = getCurrentInstance();
const global = internalInstance.appContext.config.globalProperties;

defineOptions({
  name: 'CreateFormButton'
});
const props = defineProps({
  button: DefaultMenuButton,
  selections: {
    type: Array,
    default: () => [],
  },
  formDefinition: undefined
});
const emits = defineEmits(['reload']);

watchEffect(() => {
  setFormDefinition();
});

function setFormDefinition() {

}

function isProcessForm() {
  try {
    return props.formDefinition.form.processForm;
  } catch (e) {
  }
  return false;
}

function createProcessForm() {
  let url = `/plat/work/startProcess?action=add&fullScreen=1&flowId=${props.button.processDefinitionId}`;
  global.$windowManager.open(url, {
    title: props.button.buttonName,
    close: () => emits('reload')
  });
}

function addNewForm() {
  if (isProcessForm()) {
    createProcessForm();
  } else {

  }
}
</script>
